package com.itheima.user.web;

import com.itheima.user.config.JdbcProperties;
import com.itheima.user.domain.User;
import com.itheima.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope   //自动刷新配置中心配置
public class UserController {

    @Autowired
    private UserService userService;

    /*@Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;*/
    @Autowired
    private JdbcProperties jdbcProperties;

    //读取公共配置
    @Value("${user.username}")
    private String username;

    @GetMapping("/{id}")
    public User findById(@PathVariable("id") Long id) {
        return userService.findById(id);
    }

    @GetMapping("/config")
    public String config(){
        //return  username+" "+password;
        return jdbcProperties.toString()+" "+username;
        //return jdbcProperties.toString();
    }
}
